package com.inspur.gs.sbssdl.sbyxgl.djjh.djjh.front.sbdjpz_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bff.spi.action.multidelete.BeforeMultiDeleteAction;
import com.inspur.edp.bff.api.manager.context.DeleteContext;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IEntityDataCollection;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;


public class deleteBeforeCheckVOAction extends BeforeMultiDeleteAction {

	public deleteBeforeCheckVOAction(DeleteContext context) {
		super(context);
	}
	@Override
	public void execute() {
		ArrayList<String> dataIds = getDeleteContext().getDataIds();
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			String djxzid = "ff554cce-1197-469a-88f1-814f2ed0781d";// 设备点检配置明细id
			IStandardLcp djxzlcp = iLcpFactory.createLcpByBEId(djxzid);

			for (String dataId : dataIds) {
				IEntityData data=getLcp().retrieve(dataId).getData();
				IEntityDataCollection sbdjpzmx = data.getChilds().get("sbdjpzmx");
				if (!sbdjpzmx.isEmpty()){
					throw new RuntimeException("该设备已关联点检配置，禁止删除！");
				}
			}
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
}
